<?php

/**
 * Location filter form base class.
 *
 * @package    tfe
 * @subpackage filter
 * @author     3emeIG
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedInheritanceTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseLocationFormFilter extends InscriptionFormFilter
{
  protected function setupInheritance()
  {
    parent::setupInheritance();

    $this->widgetSchema   ['date'] = new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate()));
    $this->validatorSchema['date'] = new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false))));

    $this->widgetSchema   ['heure_de_debut'] = new sfWidgetFormFilterInput();
    $this->validatorSchema['heure_de_debut'] = new sfValidatorPass(array('required' => false));

    $this->widgetSchema   ['heure_de_fin'] = new sfWidgetFormFilterInput();
    $this->validatorSchema['heure_de_fin'] = new sfValidatorPass(array('required' => false));

    $this->widgetSchema   ['salles_list'] = new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Salle'));
    $this->validatorSchema['salles_list'] = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Salle', 'required' => false));

    $this->widgetSchema->setNameFormat('location_filters[%s]');
  }

  public function addSallesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ListeSalles ListeSalles')
          ->andWhereIn('ListeSalles.id_salle', $values);
  }

  public function getModelName()
  {
    return 'Location';
  }

  public function getFields()
  {
    return array_merge(parent::getFields(), array(
      'date' => 'Date',
      'heure_de_debut' => 'Text',
      'heure_de_fin' => 'Text',
      'salles_list' => 'ManyKey',
    ));
  }
}
